function [wealthDistStats] = distStats_2Huggett(g, S_, Xstruct)
%{
%%-------------------------------------------------------------------------
Generates distribution stats for the 2-state Huggett economy
%%-------------------------------------------------------------------------
%}    
    
%%-------------------------------------------------------------------------
%Unpack Structs / Setup
    
    I = Xstruct.I;
    xjump = Xstruct.xjump;
    X_ = Xstruct.X_;
    borrowingLimit = Xstruct.borrowingLimit;
        
%%-------------------------------------------------------------------------

%%-------------------------------------------------------------------------
%Overall Distribution Stats
    
    distCDF = cumsum(sum(g*xjump, 2));
    medianInd = find(distCDF > 0.5, 1);
    xzeroind = find(X_ > 0,1)-1;
    medianVal = X_(medianInd);
    
    maxInd = find(S_(:,2) < 0, 1);
    maxWealth = X_(maxInd);
    shareNegative = distCDF(xzeroind);
    shareConstrained = distCDF(1);
    
%%-------------------------------------------------------------------------

%%-------------------------------------------------------------------------
%Conditional Wealth Stats
  
    ptoneInd = find(distCDF >= 0.999, 1);
    oneInd = find(distCDF >= 0.99, 1);    
    fiveInd = find(distCDF >= 0.95, 1);
    tenInd = find(distCDF >= 0.9, 1);
    
    wealthShareTable = zeros(5,1);
    wealthShareTable(1) = sum(sum(X_(ptoneInd:I,:).*g(ptoneInd:I,:)*xjump))./sum(sum(g(ptoneInd:I,:)*xjump));
    wealthShareTable(2) = sum(sum(X_(oneInd:I,:).*g(oneInd:I,:)*xjump))./sum(sum(g(oneInd:I,:)*xjump));
    wealthShareTable(3) = sum(sum(X_(fiveInd:I,:).*g(fiveInd:I,:)*xjump))./sum(sum(g(fiveInd:I,:)*xjump));
    wealthShareTable(4) = sum(sum(X_(tenInd:I,:).*g(tenInd:I,:)*xjump))./sum(sum(g(tenInd:I,:)*xjump));
    wealthShareTable(5) = sum(sum(X_(1:medianInd,:).*g(1:medianInd,:)*xjump))./sum(sum(g(1:medianInd,:)*xjump));
    
%%-------------------------------------------------------------------------
    wealthDistStats = round([maxWealth; wealthShareTable(1:4); 100*shareNegative; 100*shareConstrained; wealthShareTable(5); medianVal], 1);

end


